public class Text {
    class TreeNode {
        TreeNode left;
        TreeNode right;
        char val;
    }

    // 获取叶子节点的个数
    int getLeafNodeCount(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if (root.left == null && root.right == null) {
            return 1;
        }
        return getLeafNodeCount(root.left) + getLeafNodeCount(root.right);
    }


    int getKLevelNodeCount(TreeNode root, int k) {
        if (root == null) {
            return 0;
        }
        if (k == 1) {
            return 1;
        }
        return getKLevelNodeCount(root.right, k - 1) +
                getKLevelNodeCount(root.left, k - 1);
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if ((p == null && q != null) || (p != null && q == null)) {
            return false;
        }
//上述代码走完之后 要么是两个都为空 要么是两个都不为空
        if (p == null && q == null) {
            return true;
        }
//代码走到这里  两个都不为空
        if (p.val != q.val) {
            return false;
        }

//p != null && q != null  && p.val == q.val
        return isSameTree(p.left, q.left)
                && isSameTree(p.right, q.right);

    }

    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if(isSameTree(root,subRoot)){
            return true;
        }
        return isSubtree(root.left,subRoot) ||isSubtree(root.right,subRoot);
    }
}
